<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload = function () {
            document.getElementById("spantest").onclick = function () {
                this.innerText = "this 关键字";
            }
            start();
        }

        function start() {
            //自动跳转页面
            var timer1;
            var value = 4;
            //每一秒执行一次
            timer1 = setInterval(function () {
                //如果等于1就结束,跳转页面
                if (value == 1) {
                    clearTimeout(timer1)
                    // open("https://www.baidu.com/")//在新的页面打开
                    location = "https://www.baidu.com/"//在当前页面打开

                }
                document.getElementById("timer").innerHTML = value--;
                console.log(value)
            }, 1000)
        }

        function dianji1() {
            window.alert("点击1")
        }

        function dianji2() {
            alert(window.confirm("确定?"))
        }

        function dianji3() {
            alert(window.prompt("请输入信息:"))
        }

        function dianji4() {
            open("http://www.baidu.com/")
        }

        var timer;

        function dianji5() {
            timer = setTimeout(function () {
                console.log("全军出击!")
            }, 1000)
        }

        function dianji6() {
            clearTimeout(timer)
        }

        function dianji7() {
            timer = setInterval(function () {
                console.log("执行了...")
            }, 1000)
        }

        //让点击的链接不跳转
        function stop(e) {
            if (e && e.preventDefault()){
                alert("w3c");
                e.preventDefault
                alert(e.preventDefault)
            }else {
                alert("ie");
                event.returnValue = false;
            }
        }
    </script>
</head>
    <body>
        <span id="spantest">我是谁了?</span><br>
        <button onclick="dianji1()">点击1</button>
        <br>
        <button onclick="dianji2()">点击2</button>
        <br>
        <button onclick="dianji3()">点击3</button>
        <br>
        <button onclick="dianji4()">点击4</button>
        <br>
        <button onclick="dianji5()">开启定时器,1秒后执行一次</button>
        <br>
        <button onclick="dianji6()">清除定时器</button>
        <br>
        <button onclick="dianji7()">每隔一段时间执行一次</button>
        <br>
        支付成功,<span id="timer">5</span>秒后自动跳转页面
        <br>
        <button onclick="history.go(-1)">上一页</button>
        <br>
        <button onclick="history.go(1)">下一页</button>
        <br>
        <a href="https://www.baidu.com/" onclick="stop(event)">点击我会不会跳转了?</a>
    </body>
</html>